﻿namespace Vdc.Window
{
    using System;
    using System.IO;
    using System.Web.UI;
    using System.Web.UI.Design;

    internal class WindowDesigner : ControlDesigner
    {
        public override string GetDesignTimeHtml()
        {
            StringWriter writer = new StringWriter();
            HtmlTextWriter writer2 = new HtmlTextWriter(writer);
            Vdc.Window.Window component = (Vdc.Window.Window)base.Component;
            writer.Write("<table style='background-color:white;border:solid 1px;width:{0};height:{1};'>", (component.Width > 150) ? component.Width : 150, (component.Height > 100) ? component.Height : 100);
            writer.Write("<tr>");
            writer.Write("<td style='background-color:silver;height:23px;vertical-align:middle;'>");
            writer.Write("<table style='padding:0px;width:100%;height:100%;'>");
            writer.Write("<tr>");
            if (component.IconPath != "")
            {
                writer.Write("<td align='left' style='vertical-align:middle;width:20px;'>");
                writer.Write("<img style='width:16px;height:16px;' src='{0}'>", component.IconPath);
                writer.Write("</td>");
            }
            writer.Write("<td align='left' style='vertical-align:middle;font-family:Tahoma;font-size:8pt;'>");
            writer.Write("<b>{0}&nbsp;</b>", (component.Title != "") ? component.Title : "[title]");
            writer.Write("</td>");
            writer.Write("<td align='right' style='font-family:Tahoma;font-size:8pt;'>");
            if (component.ShowCloseButton)
            {
                writer.Write("[x]");
            }
            writer.Write("</td>");
            writer.Write("</tr>");
            writer.Write("</table>");
            writer.Write("</td>");
            writer.Write("</tr>");
            writer.Write("<tr>");
            writer.Write("<td style='padding:0px;vertical-align:top;'>");
            writer.Write("<div style='width:{0};height:{1};overflow:{2};'>", (component.Width > 150) ? component.Width : 150, (((component.Height > 100) ? component.Height : 100) - 0x17) - (component.ShowStatusBar ? 0x17 : 0), component.Overflow);
            if (component.Url == null)
            {
                for (int i = 0; i < component.Controls.Count; i++)
                {
                    try
                    {
                        component.Controls[i].RenderControl(writer2);
                    }
                    catch
                    {
                    }
                }
            }
            else
            {
                writer.Write(component.Url);
            }
            writer.Write("</div>");
            writer.Write("</td>");
            writer.Write("</tr>");
            if (component.ShowStatusBar)
            {
                writer.Write("<tr>");
                writer.Write("<td style='background-color:silver;height:23px;vertical-align:middle;font-family:Tahoma;font-size:8pt;'>");
                writer.Write("{0}", (component.Status != "") ? component.Status : "[status]");
                writer.Write("</td>");
                writer.Write("</tr>");
            }
            writer.Write("</table>");
            return writer.ToString();
        }

        public override bool AllowResize
        {
            get
            {
                return false;
            }
        }
    }
}

